/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import controlador.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
 *
 * @author segus
 */
public class PanelEstudiante extends javax.swing.JFrame {
    String codEst;
    /**
     * Creates new form PanelEstudiante
     */
    public PanelEstudiante(String est) {
        codEst=est;
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelMatricula = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenuMatricula = new javax.swing.JMenu();
        itemMatricular = new javax.swing.JMenuItem();
        itemCancelar = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Panel Usuario");

        javax.swing.GroupLayout panelMatriculaLayout = new javax.swing.GroupLayout(panelMatricula);
        panelMatricula.setLayout(panelMatriculaLayout);
        panelMatriculaLayout.setHorizontalGroup(
            panelMatriculaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 307, Short.MAX_VALUE)
        );
        panelMatriculaLayout.setVerticalGroup(
            panelMatriculaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 255, Short.MAX_VALUE)
        );

        jMenuMatricula.setText("Matricula Academica");
        jMenuMatricula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuMatriculaActionPerformed(evt);
            }
        });

        itemMatricular.setText("Matricular Asignatura");
        itemMatricular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMatricularActionPerformed(evt);
            }
        });
        jMenuMatricula.add(itemMatricular);

        itemCancelar.setText("Cancelar Asignatura");
        itemCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemCancelarActionPerformed(evt);
            }
        });
        jMenuMatricula.add(itemCancelar);

        jMenuBar1.add(jMenuMatricula);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelMatricula, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuMatriculaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuMatriculaActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_jMenuMatriculaActionPerformed

    private void itemMatricularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemMatricularActionPerformed
        // TODO add your handling code here:
        panelMatricula.setLayout(new GridLayout(2,2));
        this.setSize(300,130);
        JLabel labelAsig = new JLabel("Codigo de Asignatura");
        final JTextField campoAsig = new JTextField(10);
        JButton bMatricular = new JButton("Matricular");

        panelMatricula.add(labelAsig);
        panelMatricula.add(campoAsig);
        panelMatricula.add(bMatricular);

        bMatricular.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){

                String asig = campoAsig.getText();
                String msj;
                ControladorEstudiante ce = new ControladorEstudiante();
                int x = ce.verificarMatriculaEstudiante(codEst);
                switch(x){
                    case 1:
                    msj = ce.matricularAsignatura(codEst, asig);
                    break;
                    case 2:
                    msj = "Usted no puede matricularse porque tiene un promedio acumulado inferior a 3.5";
                    break;
                    case 3:
                    msj = "Usted no puede matricularse porque repite alguna materia";
                    break;
                    default:
                    msj = "ERROR";
                }
                JOptionPane.showMessageDialog(panelMatricula,msj);
                panelMatricula.removeAll();

            }
        });
    }//GEN-LAST:event_itemMatricularActionPerformed

    private void itemCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemCancelarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_itemCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PanelEstudiante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PanelEstudiante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PanelEstudiante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PanelEstudiante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PanelEstudiante("09499").setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem itemCancelar;
    private javax.swing.JMenuItem itemMatricular;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenu jMenuMatricula;
    private javax.swing.JPanel panelMatricula;
    // End of variables declaration//GEN-END:variables
}
